package com.ruoyi.web.controller.game;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.YzmStateType;
import com.ruoyi.system.domain.SgXmYanzhengma;
import com.ruoyi.system.domain.bo.YanzhengmaBo;
import com.ruoyi.system.service.ISgXmYanzhengmaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * ai 操作Controller
 * 这是内部类不暴露在外面
 * @author ruoyi
 * @since 2025-6-29
 */
@Api(value = "熊猫验证码AI处理类")
@RestController
@RequestMapping("/ai")
public class AiTrainerController extends BaseController {
    @Resource
    private ISgXmYanzhengmaService sgXmYanzhengmaService;

    @ApiOperation("获取验证码列表")
    @GetMapping("/yzm/list")
    public TableDataInfo List(SgXmYanzhengma yzm) {
        startPage();
        startOrderBy();
        List<SgXmYanzhengma> list = sgXmYanzhengmaService.selectSgXmYanzhengmaList(yzm);
        return getDataTable(list);
    }

    /**
     * 更新验证码
     */
    @ApiOperation("训练中的验证码")
    @PostMapping("training")
    public AjaxResult updateStateByTraining(@RequestBody @Valid YanzhengmaBo bo) {
        SgXmYanzhengma formBo=new SgXmYanzhengma();
        formBo.setState(YzmStateType.TRAINING.getCode());
        formBo.setId(bo.getId());
        int result =sgXmYanzhengmaService.updateSgXmYanzhengma(formBo);
        if(result>0){
            return AjaxResult.success("更新成功");
        }else{
            return AjaxResult.error("跟新失败");
        }
    }

    @ApiOperation("训练完成")
    @PostMapping("trained")
    public AjaxResult updateStateByTrained(@RequestBody @Valid YanzhengmaBo bo) {
        SgXmYanzhengma formBo=new SgXmYanzhengma();
        formBo.setState(YzmStateType.TRAINED.getCode());
        formBo.setId(bo.getId());
        int result =sgXmYanzhengmaService.updateSgXmYanzhengma(formBo);
        if(result>0){
            return AjaxResult.success("更新成功");
        }else{
            return AjaxResult.error("更新失败");
        }
    }

    @ApiOperation("训练错误")
    @PostMapping("error")
    public AjaxResult updateStateByError(@RequestBody @Valid YanzhengmaBo bo) {
        SgXmYanzhengma formBo=new SgXmYanzhengma();
        formBo.setState(YzmStateType.EXCEPTION.getCode());
        formBo.setId(bo.getId());
        int result =sgXmYanzhengmaService.updateSgXmYanzhengma(formBo);
        if(result>0){
            return AjaxResult.success("更新成功");
        }else{
            return AjaxResult.error("更新失败");
        }
    }
}
